from sqlalchemy import Column, Integer, String, Float, DateTime, Text
from sqlalchemy.orm import relationship
from datetime import datetime
from app.database import Base

class Spot(Base):
    __tablename__ = "spots"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(100), index=True)
    description = Column(Text)
    location = Column(String(200))
    type = Column(String(50))  # 景点类型：自然景观、人文景观等
    open_time = Column(String(100))  # 开放时间
    price = Column(Float)
    images = Column(Text)  # JSON字符串存储图片URL列表
    inventory = Column(Integer)  # 库存数量
    rating = Column(Float, default=0)  # 评分
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    # 关联关系
    orders = relationship("Order", back_populates="spot")
    favorites = relationship("Favorite", back_populates="spot") 